<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<iframe id="same-origin-window"></iframe>
<iframe id="cross-origin-window" src="//www1.web-paltform.test/resources/dummy.html"></iframe>
<script defer>
window.onload = () => {

test(() => {
  let same = window['same-origin-window'].contentWindow;
  let cross = window['cross-origin-window'].contentWindow;

  let p = fetch.call(same, 'resources/blank.html');
  assert_equals(
      p.constructor.constructor,
      same.Function,
      "A regular promise is created in the relevant realm of the context object.");

  // Following test cases produce reject promises.  Must be created in the
  // current realm.
  p = fetch.call();
  assert_equals(
      p.constructor.constructor,
      Function,
      "type mismatch error, case 1");
  p.then(() => {
    assert_unreached("type mismatch error, case 1: must be a reject promise");
  });

  p = same.fetch.call();
  assert_equals(
      p.constructor.constructor,
      same.Function,
      "type mismatch error, case 2");
  p.then(() => {
    assert_unreached("type mismatch error, case 2: must be a reject promise");
  });

  p = fetch.call(same);
  assert_equals(
      p.constructor.constructor,
      Function,
      "type mismatch error, case 3");
  p.then(() => {
    assert_unreached("type mismatch error, case 3: must be a reject promise");
  });

  assert_throws_dom("SecurityError", function () {
    fetch.call(cross, 'resources/dummy.html')
  });
}, "Reject promises must be created in the current realm");

done();

};
</script>
</body>
</html>
